package com.yeban.javase.day16.state.waiting;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/30
 *
 * 无限等待状态 → 锁阻塞状态
 */
public class WaitingAndBlocked {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();

        Thread t = new Thread(() -> {
            synchronized (lock) {
                try {
                    lock.wait(); // 释放锁并等待
                    System.out.println("被唤醒后，尝试重新获取锁...");
                } catch (InterruptedException e) {}
            }
        });
        t.start();

        Thread.sleep(1000);
        synchronized (lock) {
            lock.notify(); // 唤醒等待线程
            Thread.sleep(3000); // 仍然持有锁不释放
        }
    }
}
